<?xml version="1.0"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
  <!ENTITY dc "http://purl.org/dc/elements/1.1/">
  <!ENTITY dcterms "http://purl.org/dc/terms/">
  <!ENTITY foaf "http://xmlns.com/foaf/0.1/">
  <!ENTITY a "http://xmlns.heustics.org/schema/myelin/0.1/">
  <!ENTITY m "http://xmlns.heustics.org/ontology/myelin/0.1/">
]>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:fhttp="http://xmlns.4suite.org/4ss/http"
  xmlns:exslt="http://exslt.org/common"
  xmlns:xf="http://www.w3.org/2002/xforms"
  xmlns:l="http://xmlns.heustics.org/schema/i18n/0.1/"  
  xmlns:a="&a;" 
  xmlns:o="&a;DomainAccount#login"
  extension-element-prefixes="fhttp"
  exclude-result-prefixes="xsl fhttp exslt xf l a o "
>
  <xsl:variable name="o:l10n" select="a:get-l10n('&a;DomainAccount#login')"/>   
  <xsl:variable name="o:titles-l10n" select="$o:l10n/l:context[@name='titles']/*"/>
  <xsl:variable name="o:params-l10n" select="$o:l10n/l:context[@name='params']/*"/>
  
  <xsl:variable name="a:session-ttl" select="/*/@a:session-ttl"/> 
  <xsl:variable name="a:max-session-ttl" select="/*/@a:max-session-ttl"/>
  
  <xsl:template match="a:title[@key='login']" mode="a:head-content">
    <xsl:call-template name="a:head-title">
      <xsl:with-param name="title" select="$o:titles-l10n[1]"/>
    </xsl:call-template>
  </xsl:template>
  
  <xsl:template match="a:title[@key='login']" mode="a:page-header">
    <xsl:call-template name="a:page-header-title">
      <xsl:with-param name="title" select="$o:titles-l10n[1]"/>
    </xsl:call-template>
  </xsl:template>        
  
  <!-- xsl:template match="a:insufficient-rights">
    <div class="insufficient-rights">
      <p>
        <xsl:value-of select="$o:l10n/l:gentext[@key='insufficient-rights']"/>
      </p>
      <div class="spacer"/>
    </div>
  </xsl:template -->  
  
  <xsl:template name="a:label-class-attr">    
    <xsl:choose>
      <xsl:when test="@error">
        <xsl:attribute name="class">label error</xsl:attribute>
      </xsl:when>
      <xsl:otherwise>
        <xsl:attribute name="class">label</xsl:attribute>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
    
  <xsl:template match="a:title" mode="a:head-content">
    <xsl:param name="key" select="@key"/>
    <xsl:value-of select="$o:l10n/l:gentext[@key='title']"/>
  </xsl:template>
  
  <xsl:template match="a:title" mode="a:page-header">
    <xsl:param name="key" select="@key"/>
    <h1>
      <xsl:value-of select="$o:l10n/l:gentext[@key='title']"/>
    </h1>    
  </xsl:template> 
    
  <xsl:template match="*" mode="a:input-show">
    <xsl:variable name="ln" select="local-name()"/>
    <div class='input text {$ln}'>  
      <div class="key">
        <div>
          <xsl:call-template name="a:label-class-attr"/>
          <span><xsl:value-of select="$o:params-l10n[@key=$ln]"/></span>
          <div class="spacer"/>
        </div>        
        <!--div class='hint'>
          <xsl:value-of select="$a:hints-l10n[@key=$ln]"/>
        </div-->
        <div class="spacer"/>
      </div>      
      <div class='value'>
        <input type="text" value="{.}" name="{$ln}"/>
        <div class="spacer"/>
      </div>
      <div class='spacer'/>
    </div>
  </xsl:template>
  
  <xsl:template match="a:passwd" mode="a:input-show"> 
    <div class='input text passwd'>  
      <div class="key">
        <div>
          <xsl:call-template name="a:label-class-attr"/>
          <span><xsl:value-of select="$o:params-l10n[@key='passwd']"/></span>
          <div class="spacer"/>
        </div>        
        <!--div class='hint'>
          <xsl:value-of select="$a:hints-l10n[@key=$ln]"/>
        </div-->
        <div class="spacer"/>
      </div>      
      <div class='value'>
        <input type="password" value="" name="passwd"/>
        <div class="spacer"/>
      </div>
      <div class='spacer'/>
    </div>
  </xsl:template>
  
  <xsl:template match="a:domain" mode="a:input-show"> 
    <xsl:variable name="opts" select="a:options"/>
    <xsl:if test="$opts/@count &gt; 1">
    <div class='input text domain'>  
      <div class="key">        
        <div>
          <xsl:call-template name="a:label-class-attr"/>
          <span><xsl:value-of select="$o:params-l10n[@key='domain']"/></span>
          <div class="spacer"/>
        </div>  
        <div class="spacer"/>
      </div>      
      <div class='value'>    
        <div class="entry">          
          <xsl:choose>
            <xsl:when test="$opts/@count &gt; 1">
              <select name="domain">          
                <xsl:apply-templates select="$opts/*" mode="a:single-select-label">
                  <xsl:with-param name="selected" select="@selected"/>     
                </xsl:apply-templates>
              </select>    
            </xsl:when>
            <xsl:when test="$opts/@count = 1 and $opts/*[1]/@label">
              <span>
                <xsl:value-of select="$opts/*[1]/@label"/>
              </span>
            </xsl:when>
            <xsl:otherwise>
              <span>
                <xsl:value-of select="$o:params-l10n[@key='no-domains']"/>
              </span>
            </xsl:otherwise>
          </xsl:choose>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>
      <div class='spacer'/>
    </div>
    </xsl:if>
  </xsl:template>
  
  <xsl:template match="a:session-ttl" mode="a:input-show">  
    <div class='input text session_ttl'>  
      <div class="key">
        <div>
          <xsl:call-template name="a:label-class-attr"/>
          <span><xsl:value-of select="$o:params-l10n[@key='session-ttl']"/></span>
          <div class="spacer"/>
        </div>        
        <!--div class='hint'>
          <xsl:value-of select="$a:hints-l10n[@key=$ln]"/>
        </div-->
        <div class="spacer"/>
      </div>      
      <div class='value'>
        <select name='session-ttl'>          
          <xsl:call-template name="a:session-ttl">
            <xsl:with-param name="cur" select="number(@value)"/>             
          </xsl:call-template>
        </select>
        <div class="spacer"/>
      </div>
      <div class='spacer'/>
    </div>
  </xsl:template>
  
  <xsl:template name="a:session-ttl">      
    <xsl:param name="val" select="0"/> 
    <xsl:param name="cur"/>    
    <xsl:if test="$val &lt; @max">
      <xsl:variable name="new-val" select="$val + @increment"/>    
      <option value="{$new-val}">
        <xsl:if test="$new-val = $cur">
          <xsl:attribute name="selected">selected</xsl:attribute>
        </xsl:if>
        <xsl:value-of select="concat($new-val,'s')"/>
      </option>
      <xsl:call-template name="a:session-ttl">        
        <xsl:with-param name="val" select="$new-val"/>
        <xsl:with-param name="cur" select="$cur"/>
      </xsl:call-template>
    </xsl:if>    
  </xsl:template>
  
  <xsl:template match="a:submission">
    <xsl:param name="events-l10n" select="$o:l10n/l:context[@name='events']/*"/>
    <xsl:param name="name" select="@name"/>
    <div class='submits'>                  
      <xsl:apply-templates>
        <xsl:with-param name="name" select="$name"/>
        <xsl:with-param name="events-l10n" select="$events-l10n"/>      
      </xsl:apply-templates>
      <div class="spacer"/>
    </div>
  </xsl:template> 
  
  <xsl:template match="a:submit">
    <xsl:param name="name"/>
    <xsl:param name="events-l10n"/> 
    <xsl:param name="key" select="@key"/>   
    <div class="input submit">    
      <xsl:variable name="value" select="$events-l10n[@key=$key]"/>
      <input type='hidden' name='{$key}' 
        value='{$value}'/>
      <input type='submit' name='{$name}'
        value='{$value}'/>
      <div class='spacer'/>
    </div>     
  </xsl:template>
  
  <xsl:template match='a:msgs'>  
    <xsl:param name="account" select="/*/a:account"/>
    <xsl:param name="l10n" select="$o:l10n/l:context[@name='msgs']/*"/>
    <xsl:variable name="msgs-rtf">
      <xsl:apply-templates>
        <xsl:with-param name="l10n" select="$l10n"/>
      </xsl:apply-templates>
    </xsl:variable>
    <xsl:variable name="msgs" select="exslt:node-set($msgs-rtf)"/>
    <xsl:if test="$msgs">
      <ul class='msgs {@role}'>   
        <xsl:copy-of select="$msgs"/>
        <xsl:if test="$account/@logged-in">
          <xsl:call-template name="a:login-msg">
            <xsl:with-param name="l10n" select="$l10n"/>
            <xsl:with-param name="key" select="'logged-in'"/>
          </xsl:call-template>
        </xsl:if>    
      </ul>
    </xsl:if>
  </xsl:template>
  
  <xsl:template match='a:msg' name="a:login-msg">
    <xsl:param name="l10n" select="$o:l10n/l:context[@name='status']/*"/>
    <xsl:param name="key" select="@key"/>
    <xsl:param name="msg" select="$l10n[@key=$key]"/>
    <xsl:if test="string-length($msg)">
      <li class="msg {$key}">        
        <span>
          <xsl:value-of select="$msg"/>
        </span>
        <div class="spacer"/>
      </li>
    </xsl:if>
  </xsl:template>  
 
  <xsl:template match="a:form" mode='a:status'>
    <xsl:param name="key" select="string(@status-type)"/>
    <xsl:param name="l10n" select="$o:l10n/l:context[@name='status-types']/*"/>
    <xsl:variable name="status" select="$l10n[@key=$key]"/>
    <xsl:if test="$status">
      <div class="entry status">        
        <span>
          <xsl:value-of select='$status'/>
        </span>
        <div class="spacer"/>
      </div>    
    </xsl:if>
  </xsl:template>
  
  <xsl:template match="a:form">  
    <xsl:param name="config" select="/*/a:config"/>  
    <xsl:param name="account" select="/*/a:account"/>
    <xsl:variable name="model" select="xf:model"/>
    <xsl:variable name="subm" select="$model/xf:submission"/>   
    <div class="login-wrapper"> 
      <div class='login-form-container'>    
        <h2><xsl:value-of select="$o:l10n/l:gentext[@key='login-form-title']"/></h2>
        <xsl:apply-templates select="." mode="a:status"/>
        <form method='{$subm/@method}' action='{a:format-repeat-request($subm/@action)}'>
          <xsl:variable name="submission" select="a:submission"/>
          <div class="hidden">
            <input type='hidden' name='http-post-encoding' value='iso-8859-1'/>
            <input type='hidden' name='stage' value='{$submission/@stage}'/>            
            <input type='hidden' name='no-referrer' value='1'/>
            <xsl:if test="@status-type='permission'">
              <input type='hidden' name='permission' value='1'/>
            </xsl:if>
          </div>
          <div class='inputs'>            
            <xsl:apply-templates select="$model/xf:instance/*/*" mode="a:input-show">
              <xsl:with-param name="params-l10n" select="$o:l10n/l:context[@name='main-form-params']/*"/>
            </xsl:apply-templates>
          </div>
          <xsl:apply-templates select="a:submission"/>
        </form> 
        <div class="spacer"/>         
      </div>
      <xsl:variable name="rel-req-rtf">
        <xsl:apply-templates select="." mode="a:form-related-request"/>  
      </xsl:variable>
      <xsl:if test="exslt:node-set($rel-req-rtf)">
        <div class="form-related-requests login-form-related-requests">
          <xsl:copy-of select="$rel-req-rtf"/>
          <div class='spacer'/>
        </div>
      </xsl:if>
      <div class="spacer"/>
    </div>
  </xsl:template>
  
  <xsl:template match="*" mode="a:form-related-request"/>

</xsl:stylesheet>
